package com.itheima.service.Impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    private static final Logger log = LoggerFactory.getLogger(ReportServiceImpl.class);
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;
    /**
     * 统计各个职位的员工人数
     */
    @Override
    public JobOption getEmpJobData() {
        List<Map> list=empMapper.getEmpJobData();
        log.info("list:{}",list);
        List<Object> jobList = list.stream().map(map ->{
            log.info("map:{}",map);
            return map.get("name");
        } ).toList();
        List<Object> dataList = list.stream().map(map ->{
            log.info("map:{}",map);
            return map.get("value");
        } ).toList();

        log.info("jobList:{}",jobList);
        log.info("dataList:{}",dataList);

        return new JobOption(jobList,dataList);
    }

    /**
     * 统计员工性别信息
     */
    @Override
    public List<Map> getEmpGenderData() {

        return empMapper.getEmpGenderData();
    }

    /**
     * 统计学员的学历信息
     *
     * @return 返回查询到的学历信息
     */
    @Override
    public List<Map> getStudentDegreeData() {

        return studentMapper.getStudentDegreeData();
    }

    /**
     * 统计每一个班级的人数
     */
    @Override
    public StudentOption getStudentCountData() {
       List<Map> studentCountData= studentMapper.getStudentCountData();
        List<Object> clazzList = studentCountData.stream().map(map -> map.get("name")).toList();
        List<Object> dataList = studentCountData.stream().map(map -> map.get("value")).toList();
        return new StudentOption(clazzList,dataList);
    }
}
